<?php
	SESSION_START();
	//var_dump($_SESSION['user']);die;
?>
<center>
<img src="./up/<?php echo $_SESSION['user']['picname']?>">
<form action='picup.php?action=update&oldname=<?php echo $_SESSION['user']['picname']?>' method='POST' enctype="multipart/form-data">
<input type="file" name="picname" value="<?php echo $users['picname']; ?>" ><br/><br/>
<input name="" type="submit" value="提交" class="text-but">
<input name="" type="reset" value="重置" class="text-but"></td>
</form>

<?php

	include("./dbconfig.php");
	include("../../../public/functions.php");
	
	$link = @mysqli_connect(HOST,USER,PASS) or die("数据库连接失败");
	mysqli_select_db($link,DBNAME);
	mysqli_set_charset($link,"utf8");
	
	$upfile = $_FILES['picname'];
	$path = "./up/";
	$typelist = array("image/png","image/jpeg","image/jpg","image/gif","image/pjpeg"); 
	
	switch($_GET['action']){
	      case 'update':
            $picname = $_FILES['picname'];
			$picname = fileupload($upfile,$path,$typelist)['info'];
           
            $sql = "update users set picname='$picname' where id={$_SESSION['user']['id']}";
            //echo $sql;die;
			
            $result = mysqli_query($link,$sql);
            @unlink("./up/".$_GET['oldname']);
			
            header("Location:ucenter.php");
            
        break;
	}

?>

 